package com.fas.system.controller;

import com.fas.common.annotation.Log;
import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.model.LoginUser;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.enums.BusinessType;
import com.fas.common.enums.OperatorType;
import com.fas.common.utils.SecurityUtils;
import com.fas.common.utils.poi.ExcelUtil;
import com.fas.system.domain.FasEngineer;
import com.fas.system.service.IFasEngineerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工程师Controller
 * 
 * @author ruoyi
 * @date 2022-04-27
 */
@Api(tags = "工程师")
@RestController
@RequestMapping("/system/engineer")
public class FasEngineerController extends BaseController
{
    @Autowired
    private IFasEngineerService fasEngineerService;


    @ApiOperation(value = "获取总公司工程师列表")
//    @PreAuthorize("@ss.hasPermi('system:engineer:list')")
    @GetMapping("/listengineer")
    public TableDataInfo list(@RequestParam(value = "condition",required = false)String condition) {

        FasEngineer fasEngineer = new FasEngineer();
        fasEngineer.setCondition(condition);
        startPage();
        List<FasEngineer> list = fasEngineerService.selectFasEngineerlist1(fasEngineer);

        return getDataTable(list);

    }

    @ApiOperation(value = "获取维保单位工程师列表")
//    @PreAuthorize("@ss.hasPermi('system:engineer:list')")
    @GetMapping("/listengineer1")
    public TableDataInfo list1(@RequestParam(value = "condition",required = false)String condition) {
        LoginUser loginUser = SecurityUtils.getLoginUser();

        FasEngineer fasEngineer = new FasEngineer();
        fasEngineer.setCondition(condition);
        fasEngineer.setDeptId(loginUser.getDeptId());
        startPage();
        List<FasEngineer> list = fasEngineerService.selectFasEngineerlist2(fasEngineer);

        return getDataTable(list);

    }
    @ApiOperation(value = "小程序工程师信息修改")
//    @PreAuthorize("@ss.hasPermi('system:engineer:edit')")
    @Log(title = "工程师", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE)
    @GetMapping("/listengineer2")
    public int list2(@RequestBody FasEngineer fasEngineer) {

        fasEngineer.setRegistrationTime(null);
        fasEngineer.setEngineerState(null);
        fasEngineer.setCorporateName(null);
        fasEngineer.setDeptId(null);
        int is  = fasEngineerService.updateFasEngineer(fasEngineer);

        return is;

    }
    /**
     * 查询工程师列表
     */
//    @ApiOperation(value = "查询工程师列表")
//    @PreAuthorize("@ss.hasPermi('system:engineer:list')")
    @GetMapping("/list")
    public TableDataInfo list(FasEngineer fasEngineer)
    {
        startPage();
        List<FasEngineer> list = fasEngineerService.selectFasEngineerList(fasEngineer);
        return getDataTable(list);
    }
    /**
     * 任意条件查询工程师列表
     */
//    @ApiOperation(value = "任意条件查询工程师列表")
//    @PreAuthorize("@ss.hasPermi('system:engineer:listbyauto')")
    @GetMapping("/listbyauto")
    public TableDataInfo listbyauto(FasEngineer fasEngineer)
    {
        startPage();
        List<FasEngineer> list = fasEngineerService.selectFasEngineerListByAuto(fasEngineer);
        return getDataTable(list);
    }

    /**
     * 导出工程师列表
     */
//    @ApiOperation(value = "导出工程师列表")
//    @PreAuthorize("@ss.hasPermi('system:engineer:export')")
    @Log(title = "工程师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FasEngineer fasEngineer)
    {
        List<FasEngineer> list = fasEngineerService.selectFasEngineerList(fasEngineer);
        ExcelUtil<FasEngineer> util = new ExcelUtil<FasEngineer>(FasEngineer.class);
        util.exportExcel(response, list, "工程师数据");
    }

    /**
     * 获取工程师详细信息
     */
//    @ApiOperation(value = "获取工程师详细信息")
//    @PreAuthorize("@ss.hasPermi('system:engineer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fasEngineerService.selectFasEngineerById(id));
    }

    /**
     * 新增工程师
     */
//    @ApiOperation(value = "新增工程师")
//    @PreAuthorize("@ss.hasPermi('system:engineer:add')")
    @Log(title = "工程师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FasEngineer fasEngineer)
    {
        return toAjax(fasEngineerService.insertFasEngineer(fasEngineer));
    }

    /**
     * 修改工程师
     */
//    @ApiOperation(value = "小程序修改工程师")
//    @PreAuthorize("@ss.hasPermi('system:engineer:edit')")
    @Log(title = "工程师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(FasEngineer fasEngineer)
    {
//        FasEngineer.setRegistrationTime(null);
////        fasEngineer.setEngineerState(null);
////        fasEngineer.setCorporateName(null);
////        fasEngineer.setDeptId(null);
        return toAjax(fasEngineerService.updateFasEngineer(fasEngineer));
    }

    /**
     * 删除工程师
     */
//    @ApiOperation(value = "删除工程师")
//    @PreAuthorize("@ss.hasPermi('system:engineer:remove')")
    @Log(title = "工程师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fasEngineerService.deleteFasEngineerByIds(ids));
    }
}
